/************************************************************
 * Copyright (C), 2022-2030, ripnano. Co., Ltd.
 * FileName:        form_self_checking.h
 * Author:          Dan Yin
 * Date:            2024-11-11
 * Description:     functions self-checking
 * Version:         1.0.0.0
 **********************************************************/

#ifndef FORM_SELF_CHECKING_H
#define FORM_SELF_CHECKING_H

// add necessary includes here
#include "ui/defines/global.h"
#include "utils/can/can_bll_t1c.h"
#include "utils/firmware/firmware_bll.h"
#include "ui/factory/self-checking/mvc/maintain_tableview.h"
#include "ui/factory/self-checking/mvc/maintain_tablemodel.h"


namespace Ui {
class FormSelfChecking;
}

class FormSelfChecking : public QWidget
{
    Q_OBJECT

public:
    // Get an instance of "FormSelfChecking" class, if exist, return it
    static FormSelfChecking* getInstance(QWidget *pParent = nullptr);

signals:
    // Goto the setting page
    void signalShowPageSetting();

    // The signal that refresh UI info
    void signalRefreshUI();

    void signalProgressFinished(int nRowIdx);

    void signalUpdateProgressBarValue(int nRowIdx, int nValue);

    void signalUpdateResult(int nRowIdx, int nErrCode, QString sValue);

    void signalDisplayTransparentDlg(bool bShow);

private slots:
    void on_pushButton_Start_clicked();

    // The slot that refresh UI info
    void slotRefreshUI();

    // Exec an test item after click
    void slotButtonClicked(int nRowIdx, bool bAction);

    void slotUpdateProgressBarValue(int nRowIdx, int nValue);

    void slotUpdateResult(int nRowIdx, int nErrCode, QString sResult);

protected:
    // Triggers an event before it is switch language
    void changeEvent(QEvent *event);

private:
    // The default constructor
    explicit FormSelfChecking(QWidget *parent = nullptr);

    // The default destructor
    virtual ~FormSelfChecking();

    // After constructing object, initialize the object
    void _initObj();

    // Init the window style
    void _initUi();

    // Deal with all device
    void _procDetectAll();

    // Deal with detect CAN device
    int _procDetectCAN(CanBLL_T1C *pSerialbusBLL);

    // Deal with detect USB device
    int _procDetectUSB();

    // Deal with detect buzzer device
    int _procDetectBuzzer(FirmwareBLL *pFirmwareBLL);

    // Deal with detect pipette device
    int _procDetectPipette(CanBLL_T1C *pSerialbusBLL);

    // Deal with detect motion device
    int _procDetectMotion(CanBLL_T1C *pSerialbusBLL);

    // Deal with detect heating device
    int _procDetectHeating(CanBLL_T1C *pSerialbusBLL);

private:
    Ui::FormSelfChecking *ui;

    MaintainTableView   *m_pMaintainTV = nullptr;
};

#endif // FORM_SELF_CHECKING_H
